#include <bits/stdc++.h>

#define pb push_back
#define eb emplace_back
#define fi first
#define se second
#define in read<int>()
#define lin read<ll>()
#define rep(i, x, y) for(int i = (x); i <= (y); i++)
#define per(i, x, y) for(int i = (x); i >= (y); i--)

using namespace std;

using ll = long long;
using db = double;
using pii = pair < int, int >;
using vec = vector < int >;
using veg = vector < pii >;

template < typename T > T read() {
	T x = 0; bool f = 0; char ch = getchar();
	while(!isdigit(ch)) f |= ch == '-', ch = getchar();
	while(isdigit(ch)) x = x * 10 + (ch ^ 48), ch = getchar();
	return f ? -x : x;
}

template < typename T > void chkmax(T &x, const T &y) { x = x > y ? x : y; }
template < typename T > void chkmin(T &x, const T &y) { x = x < y ? x : y; }

const int N = 1e5 + 10;
const int V = 1e5;

int n, rt[N], a[N], b[N];
ll f[N];
vec G[N];

int dfn[N], tim, R[N], ind[N];
int pot[N];

void dfs(int x, int p) {
	ind[dfn[x] = R[x] = ++tim] = x;
	for(auto y : G[x]) if(y ^ p) dfs(y, x), R[x] = tim;
	if(G[x].size() == 1 && x != 1) f[x] = 0;
	else {
		f[x] = 1e18;
		rep(i, dfn[x] + 1, R[x]) {
			int y = ind[i];
			chkmin(f[x], f[y] + 1ll * a[x] * b[y]);
		}
	}
}

int main() {
#ifndef ONLINE_JUDGE
	freopen("1.in", "r", stdin); freopen("bf.out", "w", stdout);
#endif
	n = in; rep(i, 1, n) a[i] = in; rep(i, 1, n) b[i] = in;
	rep(i, 2, n) { int u = in, v = in; G[u].eb(v); G[v].eb(u); }
	dfs(1, 0); rep(i, 1, n) printf("%lld ", f[i]); puts("");
	return 0;
}
